//
//  AppActions.m
//  TestOCRedux
//
//  Created by Hotacool on 2019/1/18.
//  Copyright © 2019 Hotacool. All rights reserved.
//

#import "AppActions.h"
#import "Product.h"
#import "HStore.h"
#import "AppService.h"
#import "StepRecord.h"

void fetchProductAction(HStore *dispatcher) {
    [[AppService shareInstance] clear];
    Product * __block p;
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        p = [Product new];
        p.count = 10;
        p.consume = 0;
        [dispatcher dispatch:[HAction actionWithType:kInitialAction payload:p]];
    });
}

void autoEatAction(id dispatcher) {
    [[AppService shareInstance] requestAutoEatWithBlock:^(NSInteger add) {
        [dispatcher dispatch:[HAction actionWithType:kAutoAddAction payload:@(add)]];
    }];
}

void recordAction(id dispatcher, id obj) {
    Product *p = obj;
    [dispatcher dispatch:[HAction actionWithType:kRecordAction payload:p]];
}

void jumpToStepAction(id dispatcher, id obj) {
    [dispatcher dispatch:[HAction actionWithType:kJumpToAction payload:obj]];
}
